<template>
  <el-header>
    <div class="left">
      <el-icon
        style="font-size: 25px; cursor: pointer;"
        @click="changeCollapse"
      >
        <Menu />
      </el-icon>
      <span>OneHub 后台管理系统</span>
    </div>
    <div class="right">
      <span>欢迎 {{ store.state.userInfo.username }} 回来</span>

      <el-dropdown>
        <span class="el-dropdown-link">
          <el-icon style="font-size: 25px;">
            <UserFilled />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLogout" divided>退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { useStore } from 'vuex'
import { Menu, UserFilled } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const store = useStore()
const changeCollapse = () => {
  store.commit('changeCollapse')
}
const handleCenter = () => {
  router.push('/center')
}
const handleLogout = () => {
  localStorage.removeItem('token')
  store.commit('clearUserInfo')
  router.push('/login')
}
</script>

<style lang="scss" scoped>
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 40px;
  padding: 0 20px;
  background-color: #21252b;
  color: #fff;

  .left {
    display: flex;
    align-items: center;
    span {
      margin-left: 10px;
    }
  }

  .right {
    display: flex;
    align-items: center;
    span {
      margin-right: 10px;
    }
  }
}</style>